|
|
|
|
|
|
|
Many objects do not occupy a large portion of a scene, so many of the object-ray intersection tests yield no intersection. In that case, you can usually speed things up by performing scanline culling. |
|
|
|
|
|
|
|
|
Before starting to work on a scanline or row of pixels, you can calculate the intersection between the plane containing that scanline and the objects in the scene. If the plane does not intersect the object, none of the rays for that scanline intersect the object either, so you can skip all the ray intersection calculations for that scanline. |
|
|
|
|
|
|
|
|
Figure 17.9 shows the plane through the center of projection and a scanline. The plane does not intersect the top sphere, so none of the rays for this scanline do either. |
|
|
|
|
|
|
|
|
For convex objects such as spheres, you can make scanline culling even more useful. Suppose a scanline plane intersects an object. As the program traces rays through the pixels on the scanline, it will eventually find a ray that hits the object. It may find other rays that hit the object and then it may find a ray that does not hit the object. After that point, no more rays through this scanline will hit the object. The program can mark the object as culled for this scanline and not consider it again until it checks the next scanline. |
|
|
|
|
|
|
|
|
Similarly as the program moves down through the scanlines, it may find the first several scanline planes do not intersect an object and then some planes will intersect it. Once the program reaches another scanline plane that does not intersect the object, no other planes will intersect it. After that point, no rays will intersect the object again so it can be permanently culled. |
|
|
|
|
|
|
|
|
Example program VBRay, shown in Figure 17.10, demonstrates many of the three-dimensional techniques described so far in this book. |
|
|
|
|
|
|
|
|
Figure 17.9
Scanline culling. |
|
|
|
|
|